const app=getApp();
// pages/showOrder/showOrder.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detailMsg:{},
    imgurl: "https://shuigongbao.witlending.com/img/pinkup/",
    userInfo:{},
    flag:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
      userInfo: app.globalData.userInfo
    })
    if(options.orderid){
      app.request("withdraw_cash/order_detail",{order_id:options.orderid},true).then(res=>{
        if(res.error_code==0){
          this.setData({
            flag:false,
            detailMsg:res.data,
            index: Number(options.index)
          })
        }
      })
    }
  },
  // 点击删除
  deleteOrder(){
    const pages = getCurrentPages();
    const prevPage = pages[pages.length - 2]
    let list = prevPage.data.providentFund
    let order_id = this.data.detailMsg.order_id
    let index = this.data.index
    wx.showModal({
      content: '确定删除该订单吗？',
      success : (res=> {
        if (res.confirm) {
          app.request('withdraw_cash/delete',{order_id},true).then(res => {
            if(res.error_code == 0){
              
              list.splice(index, 1)
              prevPage.setData({
                providentFund: list
              })
              if(list.length == 0){
                prevPage.setData({
                  showFlags:true
                })
              }
              wx.navigateBack({
                delta: 1
              })
            }else{
              wx.showModal({
                content: res.error_message,
                showCancel: false
              })
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }) 
    })
  },
  // 联系客服
  contact(){
    console.log(111)
    app.aldstat.sendEvent('订单详情-连线客服', '订单详情-连线客服');    
  },
  // 点击领优惠
  discount() {
    app.aldstat.sendEvent('订单详情-领取优惠', '订单详情-领取优惠');
    let id=this.data.detailMsg.order_id;
    wx.navigateTo({
      url: `../abstract/abstract?orderid=${id}`,
    })
  },

  // 复制订单号
  copy(){
    wx.setClipboardData({
      data: this.data.detailMsg.order_id,
      success(res){
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: "社保/公积金代缴、公积金提取!",
      path: '/pages/home/home',
      imageUrl: 'https://head.image.jiajijie.com/dj/images/fiveshareBg.png',
      success: function (res) {
      },
      fail: function (res) {
        console.log(res)
      }
    }
  }
})